﻿using CDEPMS_API.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Services.Description;

namespace CDEPMS_API.Utils
{

    public class BaseApiController: ApiController
    {

        public IHttpActionResult ReturnSuccess<T>(T data, string message = "请求成功")
        {
            ApiHttpRequest apiHttpRequest = new ApiHttpRequest
            {
                status = true,
                data = data,
                message = message
            };
            return ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, apiHttpRequest));
        }

        public IHttpActionResult ReturnFail(string message = "请求失败", HttpStatusCode code = HttpStatusCode.BadRequest)
        {
            ApiHttpRequest apiHttpRequest = new ApiHttpRequest
            {
                status = false,
                message = message
            };
            return ResponseMessage(Request.CreateResponse(code, apiHttpRequest));
        }
    }
}